﻿using System.Security.Cryptography;
using System.Text;

namespace WorldmeServer.Utils
{
    public class EncryptUtils
    {
        public static string ComputeSha256Hash(string rawData)
        {
            // 创建 SHA-256 实例
            using (SHA256 sha256Hash = SHA256.Create())
            {
                // 将字符串转换为字节数组
                byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));

                // 将字节数组转换为十六进制字符串
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    builder.Append(bytes[i].ToString("x2")); // "x2" 表示两位十六进制
                }
                return builder.ToString();
            }
        }


        public static string ComputeBase64(string rawData)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(rawData);
            return Convert.ToBase64String(bytes);
        }
    }
}
